import Vue from 'vue'
import VueRouter from 'vue-router'
import HomeView from '../views/HomeView.vue'
import store from '../store'

Vue.use(VueRouter)

const routes = [
  {
    path: '/adminlogin',
    name: 'adminlogin',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: function () {
      return import(/* webpackChunkName: "about" */ '../views/adminlogin.vue')
    }
  },
  {
    path: '/home',
    name: 'home',
    component: HomeView
  },
  {
    path: '/about',
    name: 'about',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: function () {
      return import(/* webpackChunkName: "about" */ '../views/AboutView.vue')
    }
  },
  {
    path: '/login',
    name: 'login',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: function () {
      return import(/* webpackChunkName: "about" */ '../views/login.vue')
    }
  },
  {
    path: '/',
    name: 'index',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: function () {
      return import(/* webpackChunkName: "about" */ '../views/index.vue')
    },
    children:[{
      path: '',
      name: 'main',
      component: function () {
        return import(/* webpackChunkName: "about" */ '../views/main.vue')
      }
    },
    {
    path: 'activitynews',
    name: 'activitynews',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: function () {
      return import(/* webpackChunkName: "about" */ '../views/activitynews.vue')
     }
    }
    ,{
    path: 'manageconsole',
    name: 'manageconsole',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: function () {
      return import(/* webpackChunkName: "about" */ '../views/manageconsole.vue')
    },
    children:[
     {
     	path:"",
      name: "manageconsole_filemanage",
     	component: function () {
        return import(/* webpackChunkName: "about" */ '../views/filemanage.vue')
       }
     },
     {
     	path:"filemanage",
      name: 'manageconsole_filemanage',
     	component: function () {
        return import(/* webpackChunkName: "about" */ '../views/filemanage.vue')
       }
     },
     {
     	path:"projectmanage",
      name: 'manageconsole_projectmanage',
     	component: function () {
        return import(/* webpackChunkName: "about" */ '../views/projectmanage.vue')
       }
     },
     {
     	path:"accountmanage",
      name: 'accountmanage',
     	component: function () {
        return import(/* webpackChunkName: "about" */ '../views/accountmanage.vue')
       },    
       children:[{
       	path:"",
       	name: "accountmanage",
       	component: function () {
       		return import(/* webpackChunkName: "about" */ '../views/downloadsetuptemplate.vue')
       	}
       },{
       	path:"downloadsetuptemplate",
       	name: "manageconsole_accountmanage",
       	component: function () {
       		return import(/* webpackChunkName: "about" */ '../views/downloadsetuptemplate.vue')
       	}
       },{
       	path:"importaccount",
       	name: "manageconsole_accountmanage",
       	component: function () {
       		return import(/* webpackChunkName: "about" */ '../views/importaccount.vue')
       	}
       },{
       	path:"manualconfig",
       	name: "manageconsole_accountmanage",
       	component: function () {
       		return import(/* webpackChunkName: "about" */ '../views/manualconfig.vue')
       	}
       }
      ]
     }
    ]
  }
    ]
  },
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})
router.beforeEach((to, from,next) => {
   if (to.name !== 'login' && !store.getters.isLogin){
   	  return  next();
   	 if(from.name=='login')
   	  return false;
     next("login")
   }else{
   	next();
   }
})
export default router
